package lesson10;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Scanner;
import java.util.regex.Pattern;

public class Test05 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String pattern = "^c\\d{3}t$";

//        System.out.println("请输入要匹配的字符串：");
//        String input = sc.next();
//        System.out.println(input.matches(pattern));
//
//        Pattern pattern1 = Pattern.compile(pattern);
//        System.out.println(pattern1.matcher(input).find());

//        String idPattern = "^\\d{17}[\\dXx]$";
//        System.out.println("请输入身份证：");
//        String id = sc.next();
//        System.out.println(id.matches(idPattern));

//        String emailPattern = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
//        System.out.println("asb@sina".matches(emailPattern));

//        String zhPattern = "^[\\u4e00-\\u9fa5]*$";
//        System.out.println("hello".matches(zhPattern));

//        System.out.println(camelToSnake("MyFirstName"));
//        System.out.println(snakeToCamel("_my_first_name"));
//        System.out.println(formatCurrency("123456789012"));
        System.out.println(formatCurrency("12334824923.23"));
    }

    public static String camelToSnake(String name){
        String [] names = name.split("[A-Z]");
        StringBuffer sb = new StringBuffer();
        for(int i = 0;i < name.length();i++){
            if(name.charAt(i) >= 65 && name.charAt(i) <= 91 && i > 0){
                sb.append("_");
            }
            sb.append(name.charAt(i));
        }
        return sb.toString().toLowerCase();
    }
    public static String snakeToCamel(String name){
        String [] names = name.split("_");
        StringBuffer sb = new StringBuffer();
        for(int i = 0;i < names.length;i++){
            sb.append(String.valueOf(names[i].charAt(0)).toUpperCase());
            sb.append(names[i].substring(1));
        }
        return sb.toString();
    }

    public static String formatCurrency(String number){
        BigDecimal decimal = new BigDecimal(number);
        String numberStr = decimal.toString();
        String [] numberStrs = numberStr.split("\\.");
        StringBuffer oldSb = new StringBuffer(numberStrs[0]).reverse();
        StringBuffer sb = new StringBuffer();
        for(int i = 0;i < oldSb.length();i++){
            if(i % 3 == 0 && i > 0){
                sb.append(",");
            }
            sb.append(oldSb.charAt(i));
        }
        sb.reverse();
        if(numberStrs.length > 1){
            sb.append("." + numberStrs[1]);
        }
        return sb.toString();
    }
//    public static String formatCurrency(double d){
//
//        BigDecimal number=new BigDecimal(d);
//        DecimalFormat df=new DecimalFormat(",###,##0.00"); //没有小数
//        return df.format(number);
//    }

}
